<!--
 * 用户管理--重置
 * @author: hexiaozhen
 * @since: 2023-10-10
 * resetPwd.vue
-->
<template>
  <a-modal
    v-model:visible="visibleModal"
    title="提示"
    title-align="start"
    :mask-closable="false"
    draggable
    @cancel="handleCancel"
  >
    <p>请输入用户账号为"{{ rowData.userName }}"的新密码</p>
    <a-input v-model="form.password" />
    <template #footer>
      <footer>
        <a-button @click="handleCancel">取消</a-button>
        <a-button type="primary" @click="handleOk">确定</a-button>
      </footer>
    </template>
  </a-modal>
</template>

<script setup>
import { ref, toRefs } from 'vue'
import system from '@/api/modules/system'
import { Message } from '@arco-design/web-vue'
import { encrypt } from '@/utils/jsencrypt'
const props = defineProps({
  // 表单json配置项
  visible: { type: Boolean, default: false },
  rowData: {
    type: Object,
    default: () => {
      return {
        type: '',
      }
    },
  },
})
const { visible, rowData } = toRefs(props)
const emit = defineEmits(['update:visible', 'submit'])
let visibleModal = ref(false) // 弹窗显示与隐藏
visibleModal.value = visible.value
const form = ref({ password: '' })

// 确定
const handleOk = () => {
  const param = {
    password: encrypt(form.value.password.trim()),
    userId: rowData.value.userId,
  }
  system.resetPwd(param).then((res) => {
    Message.success(res.msg)
    visibleModal.value = false
    emit('update:visible', false)
    emit('submit')
  })
}
// 取消
const handleCancel = () => {
  visibleModal.value = false
  emit('update:visible', false)
}
</script>
<style scoped>
p {
  margin-bottom: 10px;
}
</style>
